<?php
if (!ob_start("ob_gzhandler")) {
  ob_start();
}

require_once '../include/config.php';
require_once '../include/utils.class.php';
require_once '../include/orm.class.php';
require_once '../include/app.class.php';

session_name(SESSION);
session_start();

$orm = new ORM();
$__sys = Utils::get_param('__sys', NULL);
if (!$__sys) {
  die('No Sys Found');
}
$app = new App($__sys, $orm);
$app_data = $app->get_data();

//NOTE: NOT GOOD
unset($_SESSION['login_err']);

if (isset($app_data->contents[$app_data->query]->__iframe) && $app_data->contents[$app_data->query]->__iframe == 1) {
  if ($__sys == 'admin') {
    echo $app_data->contents[$app_data->query]->html;
    return;
  }
  $opts = new stdClass();
  $opts->cd = 't.page_id = :v1';
  $opts->cdv = array(':v1' => $app_data->contents[$app_data->query]->id);
  $app_data->contents[$app_data->query]->__cats = $orm->get('pb_ht_category', 't.order', 'ASC', NULL, NULL, $opts)->d;
  echo json_encode($app_data->contents[$app_data->query]);
} else {
  if (file_exists($app_data->contents[$app_data->query]->html)) {
    $__inst = (isset($app_data->contents[$app_data->query]->__inst)) ? $app_data->contents[$app_data->query]->__inst : 0;
    $__file = Utils::get_param('__file', 'index');
    include $app_data->contents[$app_data->query]->html;
  }
}
?>